<template>
  <div class="songs">
    <img :src="artist.picUrl" />
    <div>
      <div class="info">
        <span class="song">歌手</span>
        <span class="name">{{ artist.name }}</span>
        <div
          class="sc"
          @click="
            sc(
              $route.params.id,
              artist.picUrl,
              artist.name,
              artist.albumSize,
              artist.mvSize
            )
          "
        >
          <img src="../../assets/collect.png" /> {{ favorite }}
        </div>

        <p v-for="(item, index) in artist.alias" :key="index">{{ item }}</p>
      </div>
      <div class="music">
        <p>
          <img class="icon" src="../../assets/music.png" />
          单曲数：{{ artist.musicSize }}
        </p>
        <p>
          <img class="icon" src="../../assets/station.png" />
          专辑数：{{ artist.albumSize }}
        </p>
        <p>
          <img class="icon" src="../../assets/mv.png" />
          MV数：{{ artist.mvSize }}
        </p>
      </div>
    </div>
    <ul class="ul">
      <li
        @click="change(index)"
        :class="{ choose: index === current }"
        v-for="(item, index) in li"
        :key="index"
      >
        {{ item }}
      </li>
    </ul>
    <div v-if="current == 0">
      <Album :list="list" />
    </div>
    <div v-if="current == 1">
      <Des :des="des" :briefDesc="briefDesc" :name="this.artist.name" />
    </div>
  </div>
</template>
<script>
import Album from "./Album";
import Des from "./des";
import { mapState } from "vuex";
export default {
  mounted() {
    this.load = this.$loading.show();
    let id = this.$route.params.id;
    let album = this.$api.album({ id });
    let artists = this.$api.artists({ id });

    Promise.all([album, artists]).then((res) => {
      this.list = res[0].hotAlbums;
      this.artist = res[1].artist;
      this.load.hide();
    });
    this.$api.artistDesc({ id }).then((res) => {
      this.des = res.introduction;
      this.briefDesc = res.briefDesc;
    });
    this.songs.map((item) =>
      item.id === id ? (this.favorite = "已收藏") : null
    );
  },
  data() {
    return {
      li: ["专辑", "歌手详情"],
      current: 0,
      list: [],
      artist: [], //人物info
      des: [],
      briefDesc: "",
      load: "",
      favorite: "收藏",
    };
  },
  methods: {
    change(index) {
      this.current = index;
    },
    sc(id, img, name, zj, mv) {
      if (this.favorite == "已收藏") {
        this.$alert({
          title: "确定要取消收藏改歌手?",
          ok: () => {
            this.$store.commit("delsongs", id);
            this.$box("取消收藏成功");
            this.favorite = "收藏";
          },
        });
      } else {
        let info = { id, img, name, zj, mv };
        this.$store.commit("addsongs", info);
        this.$box("收藏成功");
        this.favorite = "已收藏";
      }
    },
  },
  computed: {
    ...mapState(["songs"]),
  },
  components: {
    Album,
    Des,
  },
};
</script>
<style lang="less" scoped>
.songs {
  display: flex;
  margin: 30px;
  flex-wrap: wrap;
  font-family: serif;
  img {
    width: 200px;
  }
  .info {
    margin-left: 30px;
    width: 500px;
    .song {
      font-size: 12px;
      display: inline-block;
      padding: 5px;
      background-color: #c62f2f;
      border-radius: 2px;
      color: white;
    }
    .name {
      vertical-align: bottom;
      font-size: 24px;
      color: #8a8a8a;
      margin: 5px;
    }
    .sc {
      display: flex;
      align-items: center;
      justify-content: center;
      float: right;
      border: 1px solid #e1e1e2;
      border-radius: 6px;
      font-size: 12px;
      padding: 5px;
      cursor: pointer;
      img {
        width: 15px;
        margin: 0 5px;
      }
    }
    p {
      margin: 10px 40px;
      font-size: 14px;
    }
  }
  .music {
    margin: 30px;
    color: #333;
    img {
      width: 15px;
      vertical-align: top;
    }
    p {
      font-size: 14px;
      margin-top: 10px;
    }
  }
  .ul {
    margin-left: -30px;
    width: 100%;
    font-family: auto;
    list-style-type: none;
    display: -webkit-box;
    padding: 10px 0px 0 70px;
    border-bottom: 1px solid #e1e1e2;
    li {
      margin-right: 55px;
      font-size: 15px;
      height: 30px;
    }
    .choose {
      color: #c62f2f;
      border-bottom: 4px solid #c62f2f;
    }
  }
}
</style>
